<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>

<body>

    <script>
        const str = '1ab2 cab3';
        // console.log(str.replace(/\d/g, '*'), str);
        // console.log(str.replace(/\s/g, '*'), str);
        // console.log(str.replace(/\w/g, '*'), str);
        console.log(str.replace(/\W/g, '*'), str);
        console.log(str.replace(/\S/g, '*'), str);
        console.log(str.replace(/\D/g, '*'), str);

        // console.log(str.match(/\d/g), str);
        console.log(str.match(/\D/g), str);

    </script>
</body>

</html>